﻿// owner 蒋家伟

#pragma once

// qt
#include <QtWidgets>


// jsdk
#include "IResourceManagerWidget.h"

class QTreeWidget;
class QTreeWidgetItem;
namespace jsdk
{
    class ResourceManagerWidget : public QWidget, public IResourceManagerWidget
    {
        Q_OBJECT
    public:
        static OwnerPtr<ResourceManagerWidget> create(std::vector<std::wstring>&& rootFilePaths, bool isTransparent, bool isOnlyDisplayDir);

    signals:
        void deleteNodeSuccess();

    private:
        // IResourceManagerWidget
        virtual void show() override;
        virtual void refresh(std::vector<std::wstring>&& rootFilePaths) override;
        virtual void setReadOnly(bool readOnly) override;
        virtual void setHideHeader(bool isHide) override;
        virtual const QWidget* getQWidget() const override { return this; };
        virtual QWidget* getQWidget() override { return this; };

        // owner
        ResourceManagerWidget(const std::vector<std::wstring>& rootFilePaths, bool isTransparent, bool isOnlyDisplayDir);
        bool initTreeWidget(const std::vector<std::wstring>& rootFilePaths);

        // 从传入的根节点与总大小，深度递归下去计算所有节点需要显示的字节占比
        void updateNodeByteRateDisplay(QTreeWidgetItem& parentTreeItem, const qint64& totalSize);
    private slots:
        void onItemClicked(QTreeWidgetItem *pItem, int column);

    private:
        QTreeWidget* m_pTreeWidget = nullptr;
        QIcon m_deleteIcon = QIcon(u8":/Image/resource/delete.png");
        QIcon m_dirIcon = QIcon(u8":/Image/resource/dir.png");
        QIcon m_fileIcon = QIcon(u8":/Image/resource/file.png");
        bool m_isOnlyDisplayDir = false;
        bool m_isOnlyRead = true;
    };
}
